package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.UserLiveInfoApi;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class UserLiveInfoAdapter extends AppAdapter<UserLiveInfoApi.Bean.TimeListDTO> {

    public UserLiveInfoAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeTextView mTvTime;
        private ShapeTextView mTvStatus;
        private ShapeTextView mTvName;
        private ShapeTextView mTvBtn;



        private ViewHolder() {
            super(R.layout.item_user_live_info);
            mTvTime = findViewById(R.id.tv_time);
            mTvStatus = findViewById(R.id.tv_status);
            mTvName = findViewById(R.id.tv_name);
            mTvBtn = findViewById(R.id.tv_btn);
        }

        @Override
        public void onBindView(int position) {
            UserLiveInfoApi.Bean.TimeListDTO bean = getItem(position);
            mTvTime.setText(bean.getLive_date());
            mTvName.setText(bean.getTeacher_name());
            if (bean.isGenerate()){
                mTvBtn.setText("查看回放");
                mTvBtn.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_EAF1FE))
                        .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_3675FE))
                        .setStrokeWidth(1)
                        .intoBackground();
                mTvBtn.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_3675FE))
                        .intoTextColor();
            }else {
                mTvBtn.setText("回放生成中");
                mTvBtn.getShapeDrawableBuilder()
                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_FFF2E7))
                        .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_FF8018))
                        .setStrokeWidth(1)
                        .intoBackground();
                mTvBtn.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_FF8018))
                        .intoTextColor();
            }
        }
    }
}